package com.siwei.mes.service.experiment;

import com.siwei.mes.entity.experiment.ExperimentSignature;
import com.siwei.mes.mapper.experiment.ExperimentSignatureMapper;
import com.siwei.mes.service.experiment.ExperimentSignatureService;
import org.springframework.stereotype.Service;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;

import javax.annotation.Resource;
import java.util.List;

/**
 * 试验台账与电子签名关系(ExperimentSignature)表服务实现类
 *
 * @author makejava
 * @since 2025-10-28 23:46:06
 */
@Service
public class ExperimentSignatureServiceImpl implements ExperimentSignatureService {
    @Resource
    private ExperimentSignatureMapper experimentSignatureMapper;

    @Override
    public Long create(ExperimentSignature entity) {
        experimentSignatureMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(ExperimentSignature entity) {
        ExperimentSignature experimentSignature = experimentSignatureMapper.selectByPrimaryKey(entity.getId());
        assertTrue(experimentSignature == null, "试验台账与电子签名关系信息不存在");
        experimentSignatureMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        ExperimentSignature experimentSignature = experimentSignatureMapper.selectByPrimaryKey(id);
        assertTrue(experimentSignature == null, "试验台账与电子签名关系信息不存在");
        experimentSignatureMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<ExperimentSignature> getPage(PageQuery<ExperimentSignature, ExperimentSignature> query) {
        ExperimentSignature searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> experimentSignatureMapper.getList(searchParam));
    }

    @Override
    public ExperimentSignature loadById(Long id) {
        return experimentSignatureMapper.loadById(id);
    }

    @Override
    public List<ExperimentSignature> getAll(ExperimentSignature entity) {
        return experimentSignatureMapper.getList(entity);
    }
}
